<template>
<div class="list">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form
        size="small"
        :inline="true"
        :model="searchForm"
        class="demo-form-inline"
      >
        <el-form-item>
          <el-input
            size="small"
            v-model="searchForm.search"
            :placeholder="$t('plus.input_user_realname')"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            icon="Search"
            @click="searchSubmit"
            >{{$t('plus.search')}}</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table
          size="small"
          :data="tableData"
          border
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column prop="name" :label="$t('plus.title')">
            <template #default="scope">
              <div class="text-ellipsis">
                <span class="red" v-if="scope.row.isTop == 1">{{$t('plus.pinned')}}</span
                >{{scope.row.name}}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="shareImgId" :label="$t('plus.cover')">
            <template #default="scope">
              <div class="picture-box d-c-c" v-if="scope.row.shareImgId > 0">
                <img :src="scope.row.shareFilePath" :alt="$t('plus.cover')" />
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="virtualNum"
            :label="$t('plus.virtual_viewers')"
            width="70"
          ></el-table-column>
          <el-table-column prop="statusText" :label="$t('plus.live_status')"></el-table-column>
          <el-table-column prop="realStartTime" :label="$t('plus.live_start_time')">
            <template #default="scope">
              <span class="fb green">
                {{scope.row.realStartTime}}
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="realEndTime" :label="$t('plus.end_time')">
            <template #default="scope">
              <span class="fb green">
                {{scope.row.realEndTime}}
              </span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('plus.room_status')">
            <template #default="scope">
              <span class="fb red" v-if="scope.row.isDelete == 1">{{$t('plus.hide')}}</span>
              <span class="fb green" v-if="scope.row.isDelete == 0">{{$t('plus.show')}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="supplierName"
            :label="$t('plus.merchant')"
            width="70"
          ></el-table-column>
          <el-table-column
            prop="anchorName"
            :label="$t('plus.host')"
            show-overflow-tooltip
          >
            <template #default="scope">
              <div class="user-info d-s-c">
                <span class="ml10">{{scope.row.nickName}}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column :label="$t('plus.data_stats')" show-overflow-tooltip>
            <template #default="scope">
              <div>{{$t('plus.viewer_count',{place1:scope.row.viewNum})}}</div>
              <div>{{$t('plus.gift_income',{place1:scope.row.giftNum})}}</div>
              <div>{{$t('plus.order_count2',{place1:scope.row.salesNum})}}</div>
              <div>{{$t('plus.likes_count',{place1:scope.row.diggNum})}}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="sort"
            :label="$t('plus.sort')"
            width="70"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            :label="$t('plus.create_time')"
            width="130"
          ></el-table-column>
          <el-table-column fixed="right" :label="$t('plus.action')" width="120">
            <template #default="scope">
              <el-button
                v-if="scope.row.liveStatus == 0"
                @click="auditClick(scope.row)"
                type="text"
                size="small"
                >{{$t('plus.review')}}</el-button
              >
              <el-button
                @click="editClick(scope.row)"
                type="text"
                size="small"
                v-auth="'/plus/live/room/edit'"
                >{{$t('plus.modify')}}</el-button
              >
              <el-button
                @click="showGift(scope.row)"
                type="text"
                size="small"
                v-auth="'/plus/live/room/user_gift'"
                >{{$t('plus.gift_ranking')}}</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        ></el-pagination>
      </div>
    </div>

    <!--审核-->
    <Audit
      v-if="open_audit"
      :form="curModel"
      @close="closeAudit($event, 'audit')"
    ></Audit>

    <!--查看房间商品-->
    <Products
      :is_open="open_product"
      :curModel="curModel"
      @close="closeProducts"
    ></Products>

    <!--编辑-->
    <Edit :open="open_edit" :form="curModel" @close="closeEdit"></Edit>

    <!--查看房间礼物排行-->
    <Gift :is_open="open_gift" :curModel="curModel" @close="closeGift"></Gift>
  </div>
</template>

<script>
import liveApi from "@/api/live.js";
import Audit from "./dialog/Audit.vue";
import Products from "./dialog/Products.vue";
import Edit from "./dialog/Edit.vue";
import Gift from "./dialog/Gift.vue";
export default {
  components: {
    Audit,
    Products,
    Edit,
    Gift
  },
  inject: ["reload"],
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      searchForm: {
        search: ""
      },
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*编辑对象*/
      curModel: {},
      /*是否打开商品*/
      open_product: false,
      /*是否审核*/
      open_audit: false,
      /*是否打开礼物*/
      open_gift: false
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*搜索*/
    searchSubmit() {
      this.curPage = 1;
      this.getTableList();
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = {
        page: self.curPage,
        list_rows: self.pageSize,
        username: self.searchForm.search
      };
      liveApi.getRoom(Params, true).then(res => {
        self.loading = false;
        self.tableData = res.data.records;
        self.totalDataNumber = res.data.total;
      }).catch(error => {});
    },
    /*删除分类*/
    deleteClick(row) {
      let self = this;
      ElMessageBox.confirm($t("plus.confirm_delete"), $t("plus.prompt"), {
        type: "warning"
      }).then(() => {
        liveApi.deleteRoom({
          roomId: row.roomId
        }).then(data => {
          ElMessage({
            message: $t("plus.delete_success"),
            type: "success"
          });
          self.getTableList();
        });
      });
    },
    /*打开审核*/
    auditClick(item) {
      this.curModel = item;
      this.open_audit = true;
    },
    /*关闭审核*/
    closeAudit() {
      this.open_audit = false;
      this.getTableList();
    },
    /*查看商品*/
    showProduct(item) {
      this.curModel = item;
      this.open_product = true;
    },
    /*关闭商品*/
    closeProducts() {
      this.open_product = false;
    },
    /*查看礼物*/
    showGift(item) {
      this.curModel = item;
      this.open_gift = true;
    },
    /*关闭礼物*/
    closeGift() {
      this.open_gift = false;
    },
    /*打开编辑*/
    editClick(e) {
      this.curModel = e;
      this.open_edit = true;
    },
    /*关闭编辑*/
    closeEdit() {
      this.open_edit = false;
      this.getTableList();
    }
  }
};
</script>

<style lang="scss" scoped>
.picture-box {
  width: 50px;
  height: 50px;
}

.picture-box img {
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.user-info img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
</style>

